#!/usr/bin/python
# usage: combine.py eng-file chi-file align-file out-file
import os,sys,string

di="/home/scd/"

f1=file(sys.argv[1],'r')
f2=file(sys.argv[2],'r')
f3=file(sys.argv[3],'r')
f4=file(sys.argv[4],'w')

le=f1.readlines()
lc=f2.readlines()
la=f3.readlines()

if lc[0].find('\r\n')>=0:
	cending='\r\n'
else:
	cending='\n'

if le[0].find('\r\n')>=0:
	eending='\r\n'
else:
	eending='\n'

for l in la:
	w1=l.strip().split("<=>")
	enws=w1[0].strip()
	chws=w1[1].strip()
	if enws=="omitted" or chws=="omitted" or enws.find(",")>0 or chws.find(",")>0:
		pass
	else:
		ensen=enws.split(",")
		chsen=chws.split(",")
		enlist=[]
		chlist=[]
		for i in ensen:
			ien=string.atoi(i)
			enlist.append(le[ien-1][:-len(eending)])
		for j in chsen:
			ich = string.atoi(j)
			chlist.append(lc[ich-1][:-len(cending)])

		finale=" ".join(enlist).replace("  "," ")+eending
		finalc=" ".join(chlist).replace("  "," ")+cending
		f4.write(finale)
		f4.write(finalc)
		f4.write(cending)
